Add a test for my fixes from July 20th.
authorSven Herzberg <sven@imendio.com>
Tue, 22 Jul 2008 18:50:54 +0000 (18:50 +0000)
committerSven Herzberg <herzi@src.gnome.org>
Tue, 22 Jul 2008 18:50:54 +0000 (18:50 +0000)
2008-07-22  Sven Herzberg  <sven@imendio.com>

Add a test for my fixes from July 20th.

* configure.in: create gdk/tests/Makefile
* gdk/Makefile.am: include the tests subfolder
* gdk/tests/Makefile.am: create and run my test
* gdk/tests/check-gdk-cairo.c (test), (main): the test that I wrote
(passes at least for x11 and quartz backends)

svn path=/trunk/; revision=20894

ChangeLog
configure.in
gdk/Makefile.am
gdk/tests/Makefile.am [new file with mode: 0644]
gdk/tests/check-gdk-cairo.c [new file with mode: 0644]

index 48a319cbd3c0f5cf050584b67015ec02d6199e89..406fba643d3f000b2e6d71dd76fa3e2f3d488c0f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-07-22  Sven Herzberg  <sven@imendio.com>
+
+       Add a test for my fixes from July 20th.
+
+       * configure.in: create gdk/tests/Makefile
+       * gdk/Makefile.am: include the tests subfolder
+       * gdk/tests/Makefile.am: create and run my test
+       * gdk/tests/check-gdk-cairo.c (test), (main): the test that I wrote
+       (passes at least for x11 and quartz backends)
+
 2008-07-22  Frederic Crozat  <fcrozat@mandriva.com>
 
        * gdk/x11/gdkscreen-x11.c: Don't use RandR 1.2
index dc6b188f9f743b7d947239b24846d30200559219..2d1a6f9cbf193e3c0fe1be18194617dbc16c7b64 100644 (file)
@@ -2046,6 +2046,7 @@ gdk/win32/rc/Makefile
 gdk/win32/rc/gdk.rc
 gdk/quartz/Makefile
 gdk/directfb/Makefile
+gdk/tests/Makefile
 gtk/Makefile
 gtk/makefile.msc
 gtk/gtkversion.h
index fb77f36ac857aebd3a245fce19f9a03121aed754..e319e3bd139b42ae4a8feb385924b28313e0ed17 100644 (file)
@@ -1,8 +1,8 @@
 ## Makefile.am for gtk+/gdk
 include $(top_srcdir)/Makefile.decl
 
-SUBDIRS = $(gdktarget)
-DIST_SUBDIRS = win32 x11 quartz directfb
+SUBDIRS = $(gdktarget) . tests
+DIST_SUBDIRS = win32 x11 quartz directfb tests
 
 EXTRA_DIST +=                  \
        keynames.txt            \
diff --git a/gdk/tests/Makefile.am b/gdk/tests/Makefile.am
new file mode 100644 (file)
index 0000000..1e4189e
--- /dev/null
@@ -0,0 +1,20 @@
+include $(top_srcdir)/Makefile.decl
+
+NULL=
+
+check_PROGRAMS=check-gdk-cairo
+TESTS=$(check_PROGRAMS)
+
+AM_CPPFLAGS=\
+       $(GDK_DEP_CFLAGS) \
+       -I$(top_builddir)/gdk \
+       $(NULL)
+
+check_gdk_cairo_SOURCES=\
+       check-gdk-cairo.c \
+       $(NULL)
+check_gdk_cairo_LDADD=\
+       $(GDK_DEP_LIBS) \
+       $(top_builddir)/gdk-pixbuf/libgdk_pixbuf-$(GTK_API_VERSION).la \
+       $(top_builddir)/gdk/libgdk-$(gdktarget)-$(GTK_API_VERSION).la \
+       $(NULL)
diff --git a/gdk/tests/check-gdk-cairo.c b/gdk/tests/check-gdk-cairo.c
new file mode 100644 (file)
index 0000000..d1cb41b
--- /dev/null
@@ -0,0 +1,139 @@
+/* This file is part of GTK+
+ *
+ * AUTHORS
+ *     Sven Herzberg
+ *
+ * Copyright (C) 2008  Sven Herzberg
+ *
+ * This work is provided "as is"; redistribution and modification
+ * in whole or in part, in any medium, physical or electronic is
+ * permitted without restriction.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * In no event shall the authors or contributors be liable for any
+ * direct, indirect, incidental, special, exemplary, or consequential
+ * damages (including, but not limited to, procurement of substitute
+ * goods or services; loss of use, data, or profits; or business
+ * interruption) however caused and on any theory of liability, whether
+ * in contract, strict liability, or tort (including negligence or
+ * otherwise) arising in any way out of the use of this software, even
+ * if advised of the possibility of such damage.
+ */
+
+#include <gdk/gdk.h>
+#ifndef CAIRO_HAS_QUARTZ_SURFACE
+#include <cairo-quartz.h>
+#endif
+
+static void
+test (cairo_t* cr)
+{
+       cairo_save (cr);
+        cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+        cairo_paint (cr);
+       cairo_restore (cr);
+
+       cairo_move_to (cr, 10.0, 20.0);
+       cairo_line_to (cr, 10.0, 30.0);
+       cairo_stroke (cr);
+
+       cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
+       cairo_arc (cr, 0.0, 0.0, 10.0, 0.0, G_PI/2);
+       cairo_stroke (cr);
+}
+
+int
+main (int   argc,
+      char**argv)
+{
+       GdkPixmap* pixmap;
+       GdkPixbuf* pixbuf;
+       GdkPixbuf* pbuf_platform;
+       GdkPixbuf* pbuf_imagesrf;
+       GError   * error = NULL;
+       cairo_surface_t* surface;
+       cairo_t* cr;
+       guchar* data_platform;
+       guchar* data_imagesrf;
+       guint i;
+
+       gdk_init (&argc, &argv);
+
+       /* create "platform.png" via GdkPixmap */
+       pixmap = gdk_pixmap_new (NULL /* drawable */, 100 /* w */, 80 /* h */, 24 /* d */);
+       cr = gdk_cairo_create (pixmap);
+       test (cr);
+       cairo_destroy (cr);
+
+       pixbuf = gdk_pixbuf_get_from_drawable (NULL,
+                                              pixmap,
+                                              gdk_rgb_get_colormap (),
+                                              0, 0,
+                                              0, 0,
+                                              100, 80);
+       if (!gdk_pixbuf_save (pixbuf, "gdksurface.png", "png", NULL, NULL)) {
+               g_error ("Eeek! Couldn't save the file \"gdksurface.png\"");
+       }
+       g_object_unref (pixbuf);
+
+       g_object_unref (pixmap);
+
+       /* create "cairosurface.png" via pure cairo */
+#ifndef CAIRO_HAS_QUARTZ_SURFACE
+       surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 100, 80);
+#else
+       surface = cairo_quartz_surface_create (CAIRO_FORMAT_RGB24, 100, 80);
+#endif
+       cr = cairo_create (surface);
+       test (cr);
+       cairo_destroy (cr);
+       if (CAIRO_STATUS_SUCCESS != cairo_surface_write_to_png (surface, "cairosurface.png")) {
+               g_error ("Eeek! Couldn't save the file \"cairosurface.png\"");
+       }
+       cairo_surface_destroy (surface);
+
+       /* compare the images */
+       pbuf_platform = gdk_pixbuf_new_from_file ("gdksurface.png", &error);
+       if (!pbuf_platform || error) {
+               g_error ("Eeek! Error loading \"gdksurface.png\"");
+       }
+       pbuf_imagesrf = gdk_pixbuf_new_from_file ("cairosurface.png", &error);
+       if (!pbuf_imagesrf || error) {
+               g_object_unref (pbuf_platform);
+               g_error ("Eeek! Error loading \"cairosurface.png\"");
+       }
+
+       g_return_val_if_fail (gdk_pixbuf_get_width (pbuf_platform) ==
+                             gdk_pixbuf_get_width (pbuf_imagesrf),
+                             1);
+       g_return_val_if_fail (gdk_pixbuf_get_height (pbuf_platform) ==
+                             gdk_pixbuf_get_height (pbuf_imagesrf),
+                             1);
+       g_return_val_if_fail (gdk_pixbuf_get_rowstride (pbuf_platform) ==
+                             gdk_pixbuf_get_rowstride (pbuf_imagesrf),
+                             1);
+       g_return_val_if_fail (gdk_pixbuf_get_n_channels (pbuf_platform) ==
+                             gdk_pixbuf_get_n_channels (pbuf_imagesrf),
+                             1);
+
+       data_platform = gdk_pixbuf_get_pixels (pbuf_platform);
+       data_imagesrf = gdk_pixbuf_get_pixels (pbuf_imagesrf);
+
+       for (i = 0; i < gdk_pixbuf_get_height (pbuf_platform) * gdk_pixbuf_get_rowstride (pbuf_platform); i++) {
+               if (data_platform[i] != data_imagesrf[i]) {
+                       g_warning ("Eeek! Images are differing at byte %d", i);
+                       g_object_unref (pbuf_platform);
+                       g_object_unref (pbuf_imagesrf);
+                       return 1;
+               }
+       }
+
+       g_object_unref (pbuf_platform);
+       g_object_unref (pbuf_imagesrf);
+
+       return 0;
+}
+